package com.xmg.day03;

import com.xmg.day02.M;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Author: mazhongqing
 * @Date: 2020/10/21 16:17
 */
public class TLDemo {
    static ThreadLocal<M> tl = new ThreadLocal<>();

    public static void main(String[] args) {
        tl.set(new M());
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.execute(()-> {
            System.out.println(tl.get());
            tl.set(new M());
            tl.remove();
        });
        try {
            TimeUnit.MILLISECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        executorService.execute(()-> System.out.println(tl.get()));

        executorService.shutdown();
    }


}
